import { createRouter, createWebHistory } from 'vue-router';
import Login from '@/views/login/index.vue';
import Layout from '@/views/layout/index.vue';
import DwMenuFrame from '@/views/layout/frame/menu-frame/index.vue';
import DwToolbarFrame from '@/views/layout/frame/toolbar-frame/index.vue';
// import { dwHttp } from '@/utils/http'
// import { loadModule } from 'vue3-sfc-loader/dist/vue3-sfc-loader.js'
// import { reactive, type Component } from 'vue'
// import * as Vue from 'vue'
// import * as http from '@/utils/http'
// import { getMaterialFormal } from '@/api/material/material-formal'
// const data = reactive({
//   remote: null,
//   temp: '',
//   options: {
//     moduleCache: {
//       vue: Vue,
//       '@/utils/http': http,
//     },
//     //获取文件
//     async getFile(componentName: string) {
//       const identification = componentName.replace('.vue', '')
//       const { data } = await getMaterialFormal(identification)
//       const result = data as unknown as { content: string }
//       return Promise.resolve(result.content)
//     },
//     //添加样式
//     addStyle(textContent: string) {
//       console.log(textContent)
//       const style = Object.assign(document.createElement('style'), {
//         textContent,
//       })
//       const styleRef = document.head.getElementsByTagName('style')[0] || null
//       document.head.insertBefore(style, styleRef)
//     },
//   },
// })
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'login',
      component: Login,
    },
    {
      path: '/preview',
      component: () => import('../views/preview/index.vue'),
    },
    {
      path: '/map',
      component: () => import('../views/map/index.vue'),
    },
    {
      path: '/',
      name: 'layout',
      component: Layout,
      children: [
        {
          name: '/',
          path: '/',
          component: () => import('@/views/workbench/index.vue'),
          children: [],
        },
        {
          path: '/workbench',
          component: () => import('@/views/workbench/index.vue'),
        },
        {
          path: '/pm',
          name: 'pm',
          component: DwToolbarFrame,
          children: [
            {
              path: '/pm/test',
              component: () => import('@/views/test/index.vue'),
            },
            {
              path: '/pm/task/plan',
              component: () => import('@/views/pm/task-plan/index.vue'),
            },
            {
              path: '/pm/database/design',
              component: () => import('@/views/pm/db-design/index.vue'),
            },
            {
              path: '/pm/mind/map',
              component: () => import('@/views/pm/mind-map/index.vue'),
            },
            {
              path: '/pm/design/diagram',
              component: () => import('@/views/pm/design-diagram/index.vue'),
            },
            {
              path: '/pm/api/define',
              component: () => import('@/views/pm/api-define/index.vue'),
            },
          ],
        },

        {
          path: '/test',
          name: 'test',
          component: DwToolbarFrame,
          children: [
            {
              path: '/test/case',
              component: () => import('@/views/test/case/index.vue'),
            },
            {
              path: '/test/plan',
              component: () => import('@/views/test/plan/index.vue'),
            },
            {
              path: '/test/defect',
              component: () => import('@/views/test/defect/index.vue'),
            },
          ],
        },

        {
          path: '/',
          name: 'oam',
          component: DwToolbarFrame,
          children: [
            {
              path: '/oam/ssh',
              component: () => import('@/views/oam/ssh/index.vue'),
            },
            {
              path: '/oam/shell/script',
              component: () => import('@/views/oam/shell/script/index.vue'),
            },
          ],
        },

        {
          name: 'system',
          path: '/sys',
          component: DwMenuFrame,
          children: [
            {
              path: '/sys/home',
              component: () => import('@/views/sys/home/index.vue'),
            },
            {
              path: '/sys/api/mock',
              component: () => import('@/views/service/api-mock/index.vue'),
            },

            {
              path: '/sys/tag',
              component: () => import('@/views/sys/tag/index.vue'),
            },
            {
              path: '/sys/dict',
              component: () => import('@/views/sys/dict/index.vue'),
            },
            {
              path: '/sys/parameter',
              component: () => import('@/views/sys/parameter/index.vue'),
            },
            {
              path: '/sys/element',
              component: () => import('@/views/sys/element/index.vue'),
            },
            {
              path: '/sys/role',
              component: () => import('@/views/sys/role/index.vue'),
            },
            {
              path: '/sys/user',
              component: () => import('@/views/sys/user/index.vue'),
            },
            {
              path: '/sys/menu',
              component: () => import('@/views/sys/menu/index.vue'),
            },
            {
              path: '/sys/producer',
              component: () => import('@/views/sys/producer/index.vue'),
            },
            {
              path: '/sys/team',
              component: () => import('@/views/sys/team/index.vue'),
            },
            {
              path: '/sys/project',
              component: () => import('@/views/sys/project/index.vue'),
            },

            {
              path: '/assets/application',
              component: () => import('@/views/oam/assets/application/index.vue'),
            },
            {
              path: '/assets/host/machine',
              component: () => import('@/views/oam/assets/host-machine/index.vue'),
            },
            {
              path: '/sys/business/service',
              component: () => import('@/views/sys/business-service/index.vue'),
            },

            {
              path: '/gen/template/set',
              component: () => import('@/views/gen/template-set/index.vue'),
            },

            {
              path: '/sys/environment',
              component: () => import('@/views/sys/environment/index.vue'),
            },
            {
              path: '/sys/render',
              component: () => import('@/views/sys/render/index.vue'),
            },

            {
              path: '/log/login/log',
              component: () => import('@/views/log/login-log/index.vue'),
            },
            {
              path: '/log/operation/log',
              component: () => import('@/views/log/operation-log/index.vue'),
            },
            {
              path: '/sys/lock/record',
              component: () => import('@/views/sys/lock-record/index.vue'),
            },
            {
              path: '/sys/operation/document',
              component: () => import('@/views/sys/operation-document/index.vue'),
            },
            {
              path: '/report',
              component: () => import('@/views/report/index.vue'),
            },
            {
              path: '/page/table/column/standard',
              component: () => import('@/views/standard/page-table-column-standard/index.vue'),
            },
            {
              path: '/sys/team/project',
              component: () => import('@/views/sys/team/project/index.vue'),
            },

            {
              path: '/sys/notice/config',
              component: () => import('@/views/sys/notice/config/index.vue'),
            },
            {
              path: '/sys/notice/log',
              component: () => import('@/views/sys/notice/log/index.vue'),
            },
            {
              path: '/project/data/migration',
              component: () => import('@/views/sys/project-data-migration/index.vue'),
            },
          ],
        },
        {
          path: '/service',
          name: 'service',
          component: DwToolbarFrame,
          children: [
            {
              path: '/service/business/model',
              component: () => import('@/views/service/business-model/index.vue'),
            },

            {
              path: '/service/common/function',
              component: () => import('@/views/service/common-function/index.vue'),
            },
            {
              path: '/service/code/template',
              component: () => import('@/views/service/code-template/index.vue'),
            },
          ],
        },
        {
          path: '/material',
          name: 'material',
          component: DwToolbarFrame,
          children: [
            {
              path: '/material/layout/component',
              component: () => import('@/views/material/layout-component/index.vue'),
            },
            {
              path: '/material/basic/component',
              component: () => import('@/views/material/basic-component/index.vue'),
            },
            {
              path: '/material/master/page',
              component: () => import('@/views/material/master-page/index.vue'),
            },
            {
              path: '/web/common/function',
              component: () => import('@/views/material/common-function/index.vue'),
            },
            {
              path: '/web/code/template',
              component: () => import('@/views/material/code-template/index.vue'),
            },
          ],
        },
        {
          path: '/app',
          name: 'app',
          component: DwToolbarFrame,
          children: [
            {
              path: '/app/install/record',
              component: () => import('@/views/app/install/index.vue'),
            },
            {
              path: '/app/software',
              component: () => import('@/views/app/software/index.vue'),
            },
          ],
        },
        {
          path: '/datasource',
          name: 'datasource',
          component: DwToolbarFrame,
          children: [
            {
              path: '/jdbc/driver/dict',
              component: () => import('@/views/modeling/jdbc-driver-dict/index.vue'),
            },
            {
              path: '/database',
              component: () => import('@/views/modeling/database/index.vue'),
            },
            {
              path: '/database/table',
              component: () => import('@/views/modeling/database-table/index.vue'),
            },
            {
              path: '/database/column/standard',
              component: () => import('@/views/modeling/database-column-standard/index.vue'),
            },
            {
              path: '/sql/template',
              component: () => import('@/views/modeling/sql-template/index.vue'),
            },
          ],
        },
      ],
    },
  ],
});
// interface IRoute {
//   parentName?: string
//   name: string
//   path: string
//   component: string
// }
// 动态添加路由
// const addDynamicRoutes = async () => {
//   const vuePageFiles = import.meta.glob<Record<string, { default: Component }>>(
//     '../views/**/index.vue',
//     {
//       eager: true,
//     },
//   )
//   await dwHttp({
//     method: 'get',
//     isSuccessTip: false,
//     url: '/admin-api/sys/menu/route/list',
//   }).then(async (res) => {
//     const routeList = res.data as unknown as IRoute[]
//     if (!routeList || routeList.length == 0) {
//       return
//     }
//     for (let i = 0; i < routeList.length; i++) {
//       const route = routeList[i]
//       const TestIndex = await loadModule('Form@0.0.1.vue', data.options)
//       if (route.parentName) {
//         router.addRoute(route.parentName, {
//           name: route.name,
//           path: route.path,
//           component: TestIndex,
//         })
//       } else {
//         route.component = '../views/test/index.vue'
//         router.addRoute({
//           name: route.name,
//           path: route.path,
//           component: vuePageFiles[route.component].default,
//         })
//       }
//     }
//   })
// }
//根据动态添加路由
// await addDynamicRoutes()
export default router;
